import request from '@/utils/request/index.js'; // 封装的request.js文件的位置
import {
	RSA,
	AES
} from '@/utils/encryption/encrypt-tools.js'

const url_all = {
	'DEV': 'http://127.0.0.1:8082', // 开发
	'PRO': '/zizhuApi', // 生产
}

let BASEURL = url_all['PRO'] // 调整当前环境

// // 获取用户基本信息 
// export const getBaseInfo = () => {
// 	return request(`/user/basicInfo`, 'GET')
// }

// // 获取用户基本信息 参数拼接在路径
// export const getBaseInfo = (userId) => {
// 	return request(`/user/basicInfo?userId=${userId}`, 'GET')
// }

// // 获取用户基本信息 restful风格
// export const getBaseInfo = (userId) => {
// 	return request(`/user/basicInfo/userId`, 'GET')
// }

// // 获取公匙
// export const getPubKey = (loading = true) => {
// 	return request(`/user/getPubKey`, 'GET', null, loading)
// }

// // 获取公匙
// export const getPubKey = () => {
// 	return request(`/user/getPubKey`, 'GET', null, false)
// }


/**
 * 登录
 */
export const getBaseUrl = () => {
	return BASEURL
}

/**
 * 登录
 */
export const login = (params) => {
	let rsa = new RSA()
	let aes = new AES()
	aes.generateSecretKey()
	params.secretKey = rsa.encrypt(aes.secretKey)
	uni.setStorageSync('secretKey', aes.secretKey)
	params.iv = rsa.encrypt(aes.iv)
	uni.setStorageSync('iv', aes.iv)
	return request(BASEURL + `/parentApi/wxLogin`, 'POST', params, false)
}
/**
 * 登录测试
 */
export const loginTest = (params) => {
	let rsa = new RSA()
	let aes = new AES()
	aes.generateSecretKey()
	params.secretKey = rsa.encrypt(aes.secretKey)
	uni.setStorageSync('secretKey', aes.secretKey)
	params.iv = rsa.encrypt(aes.iv)
	uni.setStorageSync('iv', aes.iv)
	return request(BASEURL + `/parentApi/wxLoginTest`, 'POST', params, false)
}
/**
 * 保存家长信息
 */
export const saveParentInfo = (formData) => {
	return request(BASEURL + `/parentApi/saveParentInfo`, 'POST', formData)
}

/**
 * 查询家长信息
 */
export const queryParentInfo = () => {
	return request(BASEURL + `/parentApi/queryParentInfo`, 'POST', null)
}

/**
 * 保存家长和学生
 */
export const saveParentAndStudent = (formData) => {
	return request(BASEURL + `/parentApi/saveParentAndStudent`, 'POST', formData)
}

/**
 * 添加或修改学生
 */
export const saveStudentInfo = (formData) => {
	return request(BASEURL + `/parentApi/saveStudentInfo`, 'POST', formData)
}
/**
 * 查询默认学生信息
 */
export const queryDefaultStudent = () => {
	return request(BASEURL + `/parentApi/queryDefaultStudent`, 'POST', null)
}
/**
 * 查询学生信息
 */
export const queryStudent = (id) => {
	return request(BASEURL + `/parentApi/queryStudent`, 'POST', {
		'id': id
	})
}
/**
 * 查询学生列表
 */
export const queryStudentList = () => {
	return request(BASEURL + `/parentApi/queryStudentList`, 'POST', null)
}
/**
 * 查询学生列表
 */
export const saveDefaultStudent = (id) => {
	return request(BASEURL + `/parentApi/saveDefaultStudent`, 'POST', {
		id: id
	})
}
/**
 * 获取区域、学校、年级、班级
 */
export const orgList = (grade, org) => {
	const params = {
		'grade': grade,
		...org
	}
	// if (parentId != undefined) {
	// 	params.parentId = parentId
	// }
	return request(BASEURL + `/parentApi/orgList`, 'POST', params)
}

/**
 * 查询数据字典列表
 */
export const dictList = (dictType) => {
	return request(BASEURL + `/parentApi/dictList`, 'POST', {
		'dictType': dictType
	})
}
/**
 * 查询民族列表
 */
export const queryNationList = () => {
	return request(BASEURL + `/parentApi/queryNationList`, 'POST', null)
}

/**
 * 查询政策
 */
export const queryZhengce = (studentId, activityId) => {
	return request(BASEURL + `/parentApi/queryZhengce`, 'POST', {
		'studentId': studentId,
		'activityId': activityId
	})
}

/**
 * 阅读政策
 */
export const readZhengce = (studentId, zhengceId, activityId, shenqingFlag) => {
	return request(BASEURL + `/parentApi/readZhengce`, 'POST', {
		'studentId': studentId,
		'zhengceId': zhengceId,
		'activityId': activityId,
		'shenqingFlag': shenqingFlag
	})
}
/**
 * 查询量化标准
 */
export const loadLianghuaList = (studentId) => {
	return request(BASEURL + `/parentApi/loadLianghuaList`, 'POST', {
		'studentId': studentId
	})
}

/**
 * 保存申请
 */
export const saveShenqing = (formData) => {
	return request(BASEURL + `/parentApi/saveShenqing`, 'POST', formData)
}
/**
 * 保存申请
 */
export const saveStuLianghuaRecord = (formData) => {
	return request(BASEURL + `/parentApi/saveStuLianghuaRecord`, 'POST', formData)
}
/**
 * 查询申请
 */
export const queryShenqing = (id) => {
	return request(BASEURL + `/parentApi/queryShenqing`, 'POST', {
		'id': id
	})
}
/**
 * 查询申请
 */
export const queryShenqingById = (id) => {
	return request(BASEURL + `/parentApi/queryShenqingById`, 'POST', {
		'id': id
	})
}
/**
 * 查询量化
 */
export const queryLianghua = (studentId, activityId, shenqingId) => {
	return request(BASEURL + `/parentApi/queryLianghua`, 'POST', {
		'studentId': studentId,
		'activityId': activityId,
		'shenqingId': shenqingId
	})
}
/**
 * 加载已上传的图片
 */
export const loadImage = (imgUrl) => {
	return request(BASEURL + imgUrl, 'GET', null)
}
/**
 * 查询是否是新用户
 */
export const checkNewUser = () => {
	return request(BASEURL + `/parentApi/checkNewUser`, 'POST', null)
}

/**
 * 学生解绑
 */
export const unbindStudent = (stuId) => {
	return request(BASEURL + `/parentApi/unbindStudent`, 'POST', {
		stuId: stuId
	})
}